home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 3.1 KB | 114 lines | [TEXT/R*ch] |
- /* Written 1:17 pm Jun 12, 1986 by sdh@joevax.UUCP in uiucdcsb:net.sources.mac */
- /* ---------- "Sleep Utility" ---------- */
- /*
- The following is the source to a sleep utility. It is equivalent to the
- blit demo bounce. It clears the *entire* screen to black thus allowing you
- to leave your mac on w/o having the menu bar burned in.
-
- #include <quickdraw.h>
- #include <event.h>
- */
- #define range 12;
- #define size 32 /*should be a power of 2*/
- #define boundx 511
- #define boundy 341
-
- GrafPort myPort;
-
- int x1[size], x2[size], y1[size], y2[size], dx1, dx2, dy1, dy2;
-
-
- /* Bounce - Steve Hawley 6/13/86 Written in Aztec C V 1.06H */
-
- /* This is a Mac implementation of the bounce program written for
- the BLIT and 5620 terminals. It simply keeps track of a list of
- end points of lines, erasing the oldest and replacing it with
- one derived from the newest plus some dx and dy values */
-
-
- abs(i)
- register int i;
- {
-
- /* absolute value */
- if (i < 0) return -i;
- else return i;
- }
-
- init()
- {
- int i;
-
- dx1 = Random() % range + 4; /* create random dx's and dy's */
- dx2 = Random() % range + 4;
- dy1 = Random() % range + 4;
- dy2 = Random() % range + 4;
-
- x1[0] = abs(Random() % boundx) + 1; /* create first point */
- x2[0] = abs(Random() % boundx) + 1;
- y1[0] = abs(Random() % boundy) + 1;
- y2[0] = abs(Random() % boundy) + 1;
-
- MoveTo(x1[0], y1[0]);
- LineTo(x2[0], y2[0]); /* draw it */
-
- for (i=1; i< size; i++) { /* derive the rest of the points */
- if ( (x1[i-1] + dx1 < 0) || (x1[i-1] + dx1 > boundx))
- dx1 = -dx1;
- x1[i] = x1[i-1] + dx1;
- if ( (x2[i-1] + dx2 < 0) || (x2[i-1] + dx2 > boundx))
- dx2 = -dx2;
- x2[i] = x2[i-1] + dx2;
- if ( (y1[i-1] + dy1 < 0) || (y1[i-1] + dy1 > boundy))
- dy1 = -dy1;
- y1[i] = y1[i-1] + dy1;
- if ( (y2[i-1] + dy2 < 0) || (y2[i-1] + dy2 > boundy))
- dy2 = -dy2;
- y2[i] = y2[i-1] + dy2;
- MoveTo(x1[i], y1[i]); /* draw them */
- LineTo(x2[i], y2[i]);
- }
- }
-
-
- main ()
- {
- Rect myRect;
- register int i, j;
-
- InitGraf(&thePort);
- OpenPort(&myPort); /* create my own port so I don't need */
- /* windows and can blacken the whole screen */
-
- HideCursor();
- SetRect(&myRect, 0, 0, boundx+1, boundy+1);
- PenPat(black);
- PaintRect(&myRect); /* clear screen to black */
- PenMode(patXor); /* use exclusive-or drawing to ease animation */
- init();
- i = 0; /* oldest set of points */
- while(!Button()) { /* repeat until button is down */
- j = i-1; /* find newest points */
- if (j< 0) j = size - 1;
- MoveTo(x1[i], y1[i]); /* erase old */
- LineTo(x2[i], y2[i]);
- /* derive new point */
- if ( (x1[j] + dx1 < 0) || (x1[j] + dx1 > boundx))
- dx1 = -dx1;
- x1[i] = x1[j] + dx1;
- if ( (x2[j] + dx2 < 0) || (x2[j] + dx2 > boundx))
- dx2 = -dx2;
- x2[i] = x2[j] + dx2;
- if ( (y1[j] + dy1 < 0) || (y1[j] + dy1 > boundy))
- dy1 = -dy1;
- y1[i] = y1[j] + dy1;
- if ( (y2[j] + dy2 < 0) || (y2[j] + dy2 > boundy))
- dy2 = -dy2;
- y2[i] = y2[j] + dy2;
- MoveTo(x1[i], y1[i]); /* draw new line */
- LineTo(x2[i], y2[i]);
- i = (i + 1) & size -1; /* get oldest line */
- }
- }
- /* End of text from uiucdcsb:net.sources.mac */
-